package com.beijiteshop.libcommon.network.config

import com.beijiteshop.libcommon.login.UserInfoUtil
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response

/**
 * 请求头拦截器
 */
class HeaderInterceptor : Interceptor {

    override fun intercept(chain: Interceptor.Chain): Response {
        var token = UserInfoUtil.getInstance().getLoginInfo()?.token
        if (token.isNullOrEmpty()){
            return chain.proceed(chain.request())
        }else{
            val originalRequest = chain.request()
            token = "Bearer $token"
            val updateRequest: Request =
                originalRequest.newBuilder().header("Authorization", token).build()
            return chain.proceed(updateRequest)
        }
    }
}